import excel
from selenium import webdriver
import time
import baozou_insert_sql
Platform = "有书阁"
def Inovel_test():
    driver = webdriver.Chrome(r'D:\Program Files\python3.63\chromedriver.exe')
    driver.get("https://novel.youshuge.com/")
    driver.maximize_window()
    driver.implicitly_wait(10)
    time.sleep(1)

    # 定位账号
    driver.find_element_by_name('user_name').clear()
    driver.find_element_by_name('user_name').send_keys('{0}'.format(""))

    # 定位密码

    driver.find_element_by_name('password').clear()
    driver.find_element_by_name('password').send_keys('{0}'.format(''))

    # 点击登录
    time.sleep(6)
    driver.find_element_by_xpath('//button[@class="btn btn-block btn-primary"]').click()

    try:
        time.sleep(1)
        date_time =driver.find_element_by_xpath('//div[2]/table//tr[3]/td[1]').text
        Amount = driver.find_element_by_xpath('//div[2]/table//tr[3]/td[2]').text
        Amount_share= float(Amount)

        Amount_share = Amount_share * 0.9
        Amount_share = round(Amount_share, 2)
        # print(date_time,Amount_share)
        # res = [date_time,Amount_share,Platform]
        # return res
        baozou_insert_sql.baozou_spider_everyday_sum(date_time,Amount_share,Platform)

        # print(type(date_time),type(Amount_share))
    except Exception:
        print("获取数据失败")


# if __name__=='__main__':
#     excel.write_data_to_excel()
































# url = "https://novel.youshuge.com/login"
# rr = r.get(url=url)
# # print(rr.text)
# html = rr.text.replace("\n",'').replace('\t','').replace('\r','')
# yanzhengma = re.findall('https://novel.youshuge.com/captcha/flat(.*?)" id="captcha_change" ',html)
# # print(yanzhengma)
# codeurl = 'https://novel.youshuge.com/captcha/flat{0}'.format(yanzhengma[0])
# print(codeurl)
# valcode = requests.get(codeurl)
# f = open('valcode.png', 'wb')
# # 将response的二进制内容写入到文件中
# f.write(valcode.content)
# # 关闭文件流对象
# f.close()
# code = input('请输入验证码：')
# date={
#     "user_name": "柔情书斋",
#     "password": "qwerasdf66",
#     "captcha": "{0}".format(str(code))
# }
# url = "https://novel.youshuge.com/login"
# header ={
#     # "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
#     # "Accept-Encoding": "gzip, deflate, br",
#     # "Accept-Language": "zh-CN,zh;q=0.9",
#     # "Cache-Control": "max-age=0",
#     # "Connection": "keep-alive",
#     # "Content-Length": "72",
#     # "Content-Type": "application/x-www-form-urlencoded",
#     # "Cookie": "notice=eyJpdiI6IkxkVHVWXC9LM2RmdVd3OFpYNXpSbFlnPT0iLCJ2YWx1ZSI6InNQQ3ZWRzJcL0sxZElTZ1BIR2RPVVJqWTREamVtXC9XNU9UV3NiWU5NUUpcL1hDR2dCbzhSSVRxbHp3TWF0UUd1bWwiLCJtYWMiOiIyNWI2MWMwZDY4NzRjYmJjZmRhNDEyNTQ4ODgyMjYxMmIzNjU1Y2VmYmJiYzZlMTIyZWYwMGMxZmQ5YzRlNTBlIn0%3D; laravel_session=eyJpdiI6ImVKV05NbWMyU0tkeCtmTmJhQXZyZ2c9PSIsInZhbHVlIjoiZXB2b1E2eFRHT0tEcWFqSDhOcUhGK2FFM1wvcnpiZFwveEdHVXppdUNXbWo5WkwwNzM5NTdTVDBWRTJXbjRhdDh0OUVEN1M4VVBqNlVxMEdyNUVYeHNpUT09IiwibWFjIjoiMjg5ZjM5OTU4ZTA3MjZmYjBiZDM4ZDI1YzA0NWI3YzQzYmE3MzFlZmM1NGM3YTBkYjEwNDUzZjQwZDY4ZTFmYSJ9",
#     # "Host": "novel.youshuge.com",
#     # "Origin": "https://novel.youshuge.com",
#     # "Referer": "https://novel.youshuge.com/login",
#     "Upgrade-Insecure-Requests": "1",
#     "User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.84 Safari/537.36"
# }
# #
# rr=r.post(url=url,data=date,headers = header)
# print(rr.text)
